package com.glsc.ngateway.common.base.repo.mysql.gateway.oaflow;


import com.glsc.ngateway.common.base.domain.mysql.gateway.oaflow.TFixedincomeProcess;
import org.springframework.data.jpa.repository.JpaRepository;
import org.springframework.data.jpa.repository.Modifying;
import org.springframework.data.jpa.repository.Query;
import org.springframework.data.repository.query.Param;
import org.springframework.stereotype.Repository;
import org.springframework.transaction.annotation.Transactional;

import java.util.List;

@Repository
public interface TFixedincomeProcessRepository extends JpaRepository<TFixedincomeProcess, Long> {

    List<TFixedincomeProcess> findByNodeId(String nodeId);

    List<TFixedincomeProcess> findByNodeIdAndStatus(String nodeId, String status);

    List<TFixedincomeProcess> findByNodeIdAndTradeIdAndStatus(String nodeId, String tradeId, String status);

    List<TFixedincomeProcess> findByStatus(String status);

    List<TFixedincomeProcess> findByRequestId(String requestId);

    @Transactional
    @Modifying
    @Query(value = "update TFixedincomeProcess m set m.status = :status where m.nodeId in :nodeId ")
    void updateProcessStatus(@Param("nodeId") List<String> nodeId,@Param("status") String status);

    @Query(value = "select m from TFixedincomeProcess m where m.status != 0 and m.fixStatus = :fixStatus and m.oaStatus = :oaStatus ")
    List<TFixedincomeProcess> getProcessToDeal(@Param("fixStatus") String fixStatus,@Param("oaStatus")  String oaStatus);

    @Query(value = "select m from TFixedincomeProcess m where m.status = 0 and m.groupInfo <> '' ")
    List<TFixedincomeProcess> getGroupToDeal();

    @Query(value = "select m from TFixedincomeProcess m where m.status = 0 and m.groupInfo is null ")
    List<TFixedincomeProcess> getSingleToDeal();
}
